package com.pro.controller;

import com.pro.mapper.JsCourseCommentMapper;
import com.pro.pojo.*;
import com.pro.service.JsCourseCommentService;
import com.pro.utils.SensitiveWordsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:JsCourseCommentController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2022/1/15 14:08
 * @Author: XJR
 */
@RequestMapping("/CourceComment")
@RestController
public class JsCourseCommentController {

    @Autowired
    private JsCourseCommentService service;

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/15
     * @Content:按钮中的评论数量
     */
    @RequestMapping("/BeforeCountAll")
    public JsonData BeforeCountAll(Integer type, String status){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        Integer beforeCountAll = service.BeforeCountAll(type, status);
        return beforeCountAll!=null?JsonData.buildSuccess(beforeCountAll):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/16
     * @Content:table中的数据
     */

    @RequestMapping("/BeforeCountToday")
    public JsonData BeforeCountToday(Integer type, String status, String commentDate){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        Integer integer1 = service.BeforeCountAll(type, status);
        Integer integer2 = service.BeforeCountToday(type, status, commentDate);
        JsGoodsComment comment = new JsGoodsComment();
        comment.setGoodsCountAllComment(integer1);
        comment.setCountCommentsToday(integer2);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/15
     * @Content:layui表格中的数据
     */
    @RequestMapping("/selectBeforeTable")
    public JsonData selectBeforeTable(Integer type, String status, Integer limit, Integer page){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        List<JsComment> jsComments = service.selectBeforeTable(type, status, limit, page);
        Integer count = service.BeforeCountAll(type, status);
        return jsComments!=null?JsonData.buildSuccess(jsComments,count):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/16
     * @Content:前台查看课程详情
     */
    @RequestMapping("/selectBeforeJsCourse")
    public JsonData selectBeforeJsCourse(Integer type, Integer id){
        JsCourse jsCourse = service.selectBeforeJsCourse(type, id);
        return jsCourse!=null?JsonData.buildSuccess(jsCourse):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/17
     * @Content:查看前端人员的课程评论
     */
    @RequestMapping("/selectBeforeCourseCommentById")
    public JsonData selectBeforeCourseCommentById(Integer commodityId,Integer type){
        List<JsComment> jsCourses = service.selectBeforeCourseCommentById(commodityId, type);
        List<JsComment> listFilter = SensitiveWordsUtil.getListFilter(jsCourses);
        return listFilter!=null?JsonData.buildSuccess(listFilter):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/17
     * @Content:管理人员按钮中的数据
     */
    @RequestMapping("/UserCountAll")
    public JsonData UserCountAll(Integer type,String status){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        Integer integer = service.UserCountAll(type, status);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/17
     * @Content:tbale中的数据
     */
    @RequestMapping("/UserCountToday")
    public JsonData UserCountToday(Integer type,String status,String commentDate){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        Integer integer1 = service.UserCountAll(type, status);
        Integer integer2 = service.UserCountToday(type, status, commentDate);
        JsGoodsComment comment = new JsGoodsComment();
        comment.setGoodsCountAllComment(integer1);
        comment.setCountCommentsToday(integer2);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/17
     * @Content:layuiTable中的数据
     */
    @RequestMapping("/selectUserTable")
    public JsonData selectUserTable(Integer type,String status,Integer limit,Integer page){
        status = status!=null&&!status.equals("")?"%"+status+"%":"%%";
        page = (page-1)*limit;
        List<JsComment> jsComments = service.selectUserTable(type, status, limit, page);
        return jsComments!=null?JsonData.buildSuccess(jsComments):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/16
     * @Content:后台查看课程详情
     */
    @RequestMapping("/selectUserJsCourse")
    public JsonData selectUserJsCourse(Integer type,Integer id){
        JsCourse jsCourse = service.selectUserJsCourse(type, id);
        return jsCourse!=null?JsonData.buildSuccess(jsCourse):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/17
     * @Content:根据id查询后台人员评论的课程详情
     */
    @RequestMapping("/selectUserCourseCommentById")
    public JsonData selectUserCourseCommentById(Integer commodityId,Integer type){
        List<JsComment> jsComments = service.selectUserCourseCommentById(commodityId, type);
        List<JsComment> listFilter = SensitiveWordsUtil.getListFilter(jsComments);
        return listFilter!=null?JsonData.buildSuccess(listFilter):JsonData.buildError("服务器发生错误");
    };
}
